package com.coocaa.ops.admin.v1.auth.sys;

import com.coocaa.ops.admin.base.annotation.Auth;
import com.coocaa.ops.admin.base.controller.MgrBaseController;
import com.coocaa.ops.admin.base.util.WebUtil;
import com.coocaa.ops.admin.v1.auth.sys.service.impl.SysAuthorizeServiceImpl;
import com.coocaa.ops.admin.v1.auth.sys.service.impl.SysUserServiceImpl;
import com.coocaa.ops.common.core.base.enums.AuthEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author bijiahao
 * @date : 2019/3/14.
 * @description: 系统权限 主控制器
 *
 */
@RestController
@RequestMapping("/v1")
public class SysAuthorizeMainController extends MgrBaseController {
    @Autowired
    private SysAuthorizeServiceImpl sysAuthorizeService;
    @Autowired
    private SysUserServiceImpl sysUserService;

    /**
     * 获取系统菜单
     *
     * @param request
     * @return
     */
    @Auth(verifyAuthority = true, authorityType = AuthEnum.BROWSER)
    @RequestMapping(value = "/getMenus",method = {RequestMethod.GET,RequestMethod.POST}, produces = "text/html;charset=UTF-8")
    public Object getMenus(HttpServletRequest request) {
        return sysAuthorizeService.getUserMenusByUser(WebUtil.getCurrentUser(request));
    }

    @RequestMapping(value = "/updatePassword", method = {RequestMethod.GET,RequestMethod.POST},produces = "text/html;charset=UTF-8")
    public Object updatePassword(HttpServletRequest request, @RequestParam String oldpwd, @RequestParam String newpwd, @RequestParam String newpwd2) throws Exception{
        return sysUserService.updatePassword(oldpwd, WebUtil.getCurrentUser(request), newpwd, newpwd2);
    }
}
